package com.common.android.utils.smiley;
import com.product.android.utils.LogUtils;

import android.database.Cursor;
import android.provider.BaseColumns;


public class SmileyHistoryTable implements  BaseColumns {
	public static final String TABLE_NAME = "uu_smiley_history";
	public static final String FIELD_UID= "uid";
	public static final String FIELD_SMILEY_ID= "smiley_id";
	public static final String FIELD_NAME= "name";
	public static final String FIELD_PATH= "path";
	public static final String FIELD_TIME= "time";
	public static final String FIELD_TIP= "tip";
	public static final String FIELD_SHORTCUT= "shortcut";
	
	public static final String[] TABLE_COLUMNS = new String[] { 
		 _ID,
	     FIELD_UID,
	     FIELD_SMILEY_ID,
	     FIELD_SMILEY_ID,
	     FIELD_TIME,
	     FIELD_TIP,
	     FIELD_SHORTCUT
	};

	public static final String CREATE_TABLE = "create table "
         + TABLE_NAME + " (" 
         + _ID + " integer , "
         	+ FIELD_UID + " long not null ,"
         	+ FIELD_SMILEY_ID + " INT ,"
         	+ FIELD_PATH + " TEXT ,"
         	+ FIELD_NAME + " TEXT ,"
         	+ FIELD_TIME + " LONG ,"
         	+ FIELD_TIP  + " TEXT ,"
         	+ FIELD_SHORTCUT + " TEXT ,"
         	+ " constraint pk_t2 primary key ("
	    	+ FIELD_UID+","
	    	+ FIELD_SMILEY_ID+""
	    	+ ")"
	    	+ ")";
	
	public static final String CREATE_INDEX="CREATE INDEX "
		+ TABLE_NAME
		+"_INDEX1 ON "
		+TABLE_NAME	+"("
		+FIELD_UID
		+")";
	
	public static final String TAG = "UserInfo";
	
	public static Smiley parseCursor(Cursor cursor) {
	    if (null == cursor || 0 == cursor.getCount()) {
	        LogUtils.w(TAG, "Cann't parse Cursor, bacause cursor is null or empty.");
	        return null;
	    }
	    Smiley smiley=new Smiley();
	    smiley.lastUsedTime=(cursor.getLong(cursor.getColumnIndex(FIELD_TIME)));
	    smiley.id=(cursor.getInt(cursor.getColumnIndex(FIELD_SMILEY_ID)));
	    smiley.name=(cursor.getString(cursor.getColumnIndex(FIELD_NAME)));
	    smiley.tip=(cursor.getString(cursor.getColumnIndex(FIELD_TIP)));
	    smiley.shortCut=(cursor.getString(cursor.getColumnIndex(FIELD_SHORTCUT)));
	    smiley.path=(cursor.getString(cursor.getColumnIndex(FIELD_PATH)));
	    return smiley;
	}
}